import { Entity, PrimaryGeneratedColumn, Column, UpdateDateColumn, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { TableInfo } from './tableInfo.entity';
@Entity('index_info') // 请替换为实际的表名
export class IndexInfo {
    @PrimaryGeneratedColumn({
        name: 'id',
        comment: 'ID'
    })
    id!: number;
    @Column({
        name: 'status',
        type: 'tinyint',
        default: 1,
        nullable: false,
        comment: '状态(0-禁用,1-正常)'
    })
    status?: number;

    @CreateDateColumn({
        name: 'created_at',
        type: 'datetime',
        default: () => 'CURRENT_TIMESTAMP',
        nullable: false,
        comment: '创建时间',
        precision: 0
    })
    createdAt!: Date;

    @UpdateDateColumn({
        name: 'updated_at',
        type: 'datetime',
        default: () => 'CURRENT_TIMESTAMP',
        onUpdate: 'CURRENT_TIMESTAMP',
        nullable: false,
        comment: '更新时间',
        precision: 0
    })
    updatedAt!: Date;

    @Column({
        name: 'filed_name',
        comment: '字段名称(多选)',
        type: 'varchar',
        length: 255,
    })
    filedName!: string;

    @Column({
        name: 'comment',
        type: 'varchar',
        length: 255,
        nullable: true,
        comment: '备注'
    })
    comment?: string | null;

    @Column({
        name: 'index_type',
        type: 'enum',
        enum: ['INDEX', 'UNIQUE'],
        comment: '索引类型(INDEX:普通索引, UNIQUE:唯一索引)'
    })
    indexType?: 'INDEX' | 'UNIQUE';

    @Column({
        name: 'parent_id',
        type: 'int',
        nullable: false,
        comment: '父级字段ID'
    })
    parentId!: number;

    @ManyToOne(() => TableInfo, tableInfo => tableInfo.indexInfoList,{
        createForeignKeyConstraints: false // 不创建外键约束

    })
    @JoinColumn({ name: 'parent_id' }) 
    tableInfo!: TableInfo;

    /**小驼峰字段名，不作为表字段 */
    smallHumpCode?:string;

}